﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using MixScript.BLL.FI;
using MixScriptWeb.control;
using System.Data;


namespace MixScriptWeb.Accounting
{
    public partial class frmAccInterface : cCommonWeb, IMIxCommon // System.Web.UI.Page
    {
        static DataSet ds;
        protected void Page_Load(object sender, EventArgs e)
        {
            LoadData();
        }
        private void LoadData()
        {
            ds = new DataSet();
            FillDropDownList(ddlCurrency, "mst_currency", "currency", "currency", true);
            cAccInterface acc = new cAccInterface();
            ds = acc.GetDataInterface();
            if (ds.Tables[1].Rows.Count != 0)
            {


                txtRetEarningLY.Text = ds.Tables[0].Rows[0].ItemArray[0].ToString();
                txtRetEarningLY.Lbl.Text = ds.Tables[0].Rows[0].ItemArray[1].ToString();
            }
            if (ds.Tables[2].Rows.Count != 0)
            {
                txtRetEarning.Text = ds.Tables[1].Rows[0].ItemArray[0].ToString();
                txtRetEarning.Lbl.Text = ds.Tables[1].Rows[0].ItemArray[1].ToString();
            }
            if (ds.Tables[3].Rows.Count != 0)
            {
                txtGainInForex.Text = ds.Tables[2].Rows[0].ItemArray[0].ToString();
                txtGainInForex.Lbl.Text = ds.Tables[2].Rows[0].ItemArray[1].ToString();
            }
            if (ds.Tables[4].Rows.Count != 0)
            {
                txtLostInForex.Text = ds.Tables[3].Rows[0].ItemArray[0].ToString();
                txtLostInForex.Lbl.Text = ds.Tables[3].Rows[0].ItemArray[1].ToString();
            }

            gvPurchaserawMat.DataSource = ds.Tables[4];
            gvPurchaserawMat.DataBind();
            gvPurchaseSupplier.DataSource = ds.Tables[5];
            gvPurchaseSupplier.DataBind();
            gvDirectLaborCost.DataSource = ds.Tables[6];
            gvDirectLaborCost.DataBind();
            gvProdExpense.DataSource = ds.Tables[7];
            gvProdExpense.DataBind();



            addFindClickAttribute(this, new MixScriptTB[] { txtRetEarningLY }, new string[] { "SRCACC" });
            addFindClickAttribute(this, new MixScriptTB[] { txtRetEarning }, new string[] { "SRCACC" });
            addFindClickAttribute(this, new MixScriptTB[] { txtGainInForex }, new string[] { "SRCACC" });
            addFindClickAttribute(this, new MixScriptTB[] { txtLostInForex }, new string[] { "SRCACC" });
            addFindClickAttribute(this, new MixScriptTB[] { txtPurchaseRawMat }, new string[] { "SRCACC" });
            addFindClickAttribute(this, new MixScriptTB[] { txtPurchaseSupplier }, new string[] { "SRCACC" });
            addFindClickAttribute(this, new MixScriptTB[] { txtDirectLaborCost }, new string[] { "SRCACC" });
            addFindClickAttribute(this, new MixScriptTB[] { txtProdExpense }, new string[] { "SRCACC" });

        }
        protected void btnRetEarningLY_click(Object sender, EventArgs e)
        {
            if (txtRetEarningLY.Text != "")
            {
                cAccInterface ca = new cAccInterface();
                ca.UpdateIntoInterface(ddlCurrency.SelectedItem.Value, txtRetEarningLY.Text.TrimEnd(), "1");
                LoadData();
            }
        }
        protected void btnRetEarningCY_click(Object sender, EventArgs e)
        {
            if (txtRetEarning.Text != "")
            {
                cAccInterface ca = new cAccInterface();
                ca.UpdateIntoInterface(ddlCurrency.SelectedItem.Value, txtRetEarning.Text.TrimEnd(), "2");
                LoadData();
            }
        }
        protected void btnGaininForex_click(Object sender, EventArgs e)
        {
            if (txtGainInForex.Text != "")
            {
                cAccInterface ca = new cAccInterface();
                ca.UpdateIntoInterface(ddlCurrency.SelectedItem.Value, txtGainInForex.Text.TrimEnd(), "3");
                LoadData();
            }
        }
        protected void btnLostInForex_click(Object sender, EventArgs e)
        {
            if (txtLostInForex.Text != "")
            {
                cAccInterface ca = new cAccInterface();
                ca.UpdateIntoInterface(ddlCurrency.SelectedItem.Value, txtLostInForex.Text.TrimEnd(), "4");
                LoadData();
            }
        }
        protected void btnPurchaseRawMaterial_click(Object sender, EventArgs e)
        {
            if (txtPurchaseRawMat.Text != "")
            {
                cAccInterface ca = new cAccInterface();
                ca.insertIntoInterface(ddlCurrency.SelectedItem.Value, txtPurchaseRawMat.Text.TrimEnd(), "5");
                LoadData();
            }
        }
        protected void btnProductSupplier_click(Object sender, EventArgs e)
        {
            if (txtPurchaseSupplier.Text != "")
            {
                cAccInterface ca = new cAccInterface();
                ca.insertIntoInterface(ddlCurrency.SelectedItem.Value, txtPurchaseSupplier.Text.TrimEnd(), "6");
                LoadData();
            }
        }
        protected void btnDirectLaborCost_click(Object sender, EventArgs e)
        {
            if (txtDirectLaborCost.Text != "")
            {
                cAccInterface ca = new cAccInterface();
                ca.insertIntoInterface(ddlCurrency.SelectedItem.Value, txtDirectLaborCost.Text.TrimEnd(), "7");
                LoadData();
            }
        }
        protected void btnSaveProductExpense_click(Object sender, EventArgs e)
        {
            if (txtProdExpense.Text != "")
            {
                cAccInterface ca = new cAccInterface();
                ca.insertIntoInterface(ddlCurrency.SelectedItem.Value, txtProdExpense.Text.TrimEnd(), "8");
                LoadData();
            }
        }
        protected void Delete_Interface(Object sender, GridViewCommandEventArgs e)
        {

            if (e.CommandName == "DEL")
            {
                cAccInterface ca = new cAccInterface();
                ca.DeleteInterface(e.CommandArgument.ToString());
                LoadData();
            }
        }
        public void AddFindSingle(Page p, MixScriptTB[] mtb, Label[] lb)
        {
            try
            {
                int i = 0;


                foreach (MixScriptTB m in mtb)
                {
                    System.Web.UI.WebControls.Image im = (System.Web.UI.WebControls.Image)m.FindControl("imgFind");
                    im.Attributes.Add("onclick", "return browseCOA('" + p.Form.ClientID + "', '" + m.ClientID + "_txt','" + m.ClientID + "_lbl','" + lb[i].ClientID + "','" + m.ClientID + "_hf" + "');");
                    i++;

                }
            }
            catch (Exception ex)
            {

                throw ex;
            }
        }
        public void AddFindMultiple(Page p, MixScriptTB[] mtb, Label[] lb)
        {
            try
            {
                int i = 0;
                foreach (MixScriptTB m in mtb)
                {
                    System.Web.UI.WebControls.Image im = (System.Web.UI.WebControls.Image)m.FindControl("imgFind");
                    im.Attributes.Add("onclick", "return browseCOA('" + p.Form.ClientID + "', '" + m.ClientID + "_txt','" + m.ClientID + "_lbl','" + lb[i].ClientID + "','" + m.ClientID + "_hf" + "');");
                    i++;

                }
            }
            catch (Exception ex)
            {

                throw ex;
            }
        }

        public bool isvalid()
        {

            return true;
        }
    }
}